/* 数组去重 */

// 1.无限制
function deWeight(arr) {
  let temp = [];
  for (let i = 0; i < arr.length; i++) {
    if (temp.indexOf(arr[i]) < 0) {
      temp.push(arr[i]);
    }
  }
  return temp;
}

let arr1 = [1, 2, 1, 1, 2, 3, 3, 3, 3, 4, 4, 5];
let arr = deWeight(arr1);
console.log(arr, arr1);

console.log("-------------------分割线------------------");

// 2.原地算法
function deWeight2(arr) {
  for (let i = 0; i < arr.length; i++) {
    for (let j = i + 1; j < arr.length; j++) {
      if (arr[i] === arr[j]) {
        arr.splice(j, 1);
        j--;
      }
    }
  }
}

const a = {};
const b = { c: 1 };
const arr2 = [
  1,
  1,
  "1",
  "1",
  {},
  {},
  { c: 1 },
  { c: 1 },
  a,
  a,
  b,
  b,
  [],
  [],
  [1],
  [1],
  undefined,
  undefined,
  null,
  null,
  NaN,
  NaN,
];
deWeight2(arr2);
console.log(arr2);
